<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Sugus
 * @version 	: 1.1
 * COPYRIGHT    : 2011
 * ------------------------------------------------------
 *
 * Created on	:  Mar 08, 2011
 *
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );
RClassesImporter::cls('controllers.AbstractFrontController');

class VideoFrontController extends AbstractFrontController {
	/**
	 *
	 * Main model
	 * @var VideoModel
	 */
	var $_model;

	/**
	 *
	 * Constructor
	 */
	function __construct() {
		parent::__construct();
		SysApplication::importModelCls('VideoModel');
		$this->_model = new VideoModel();
	}
	
	/**
	 * (non-PHPdoc)
	 * @see src/core/mvc/AbstractController::display()
	 */
	function display() {
		SysResponse::addJavascriptFile(SYS_TMPL_URL.'sugus/javascript/jquery-1.4.4.min.js');
		SysResponse::addJavascriptFile(SYS_TMPL_URL.'sugus/javascript/jquery.prettyPhoto.js');
		SysResponse::addStyleSheetFile(SYS_TMPL_URL.'sugus/css/prettyPhoto.css', 'screen');
		$script = '$(document).ready(function(){
			$(".video-item a[rel^=\'prettyPhoto\']").prettyPhoto({animationSpeed:\'slow\',theme:\'facebook\',slideshow:2000, autoplay_slideshow: false});
		});';
		SysResponse::addJavascriptContent($script);
		$model = $this->_model;
		RClassesImporter::cls('SugusHelper');
		$setting = SugusHelper::getSettingByName('video_per_page');
		$limit = ($setting) ? $setting->gvalue : 6;
		
		$ypage = SysRequest::getVar('vpage', 1);
		$videos = $model->getVideoPaging($ypage, $limit);
		$videoItems = $videos->getRecordSet();
		$videoList = '';
		$addi = ' style="margin-bottom:10px"';
		$playerURL = SYS_ROOT_URL.'libraries/player/video/player.swf';
		$count = 0;
		foreach ($videoItems as $vid) {
			$count++;
			$videoLink = $vid->link;
			$videoName = $vid->name;
			$link = explode('?', $videoLink);
			$link2 = explode('/', $link[0]);
			$link1 = explode('=', $link[1]);
			$newLink = implode('/', array($link2[0], '', $link2[2], $link1[0], $link1[1]));
			$newLink .= '?fs=1&amp;hl=en_US&amp;showinfo=0&amp;showsearch=0&amp;rel=0';
			eval('$videoList .= "'.SysApplication::loadTemplate('front/video-item').'";');
			if($count % 2 == 0) {
				$videoList .= '<div class="clearboth"></div>';
			}
		}
		$pagerVideo = SysTemplate::getPaginationInstance($videos->getTotalRecords(), $limit, "?vpage");
		$pagerVideo->setPagerText('<<','<','>','>>');
		$pagingVideoHtml = $pagerVideo->renderPager($ypage);
		$linker = new SiteResource('video', 'display');
		$videoShowLink = $linker->getLink();
		$titleVideo = SYS_ROOT_URL.'templates/sugus/images/logo-video.png';
		eval('echo "'.SysApplication::loadTemplate('front/display').'";');
	}
	
}